<template>
    <view class="box">
		<scroll-view class="scroll-v list" enableBackToTop="true" scroll-y >
			<view  class="guwen" v-for="guwen in gwList" :key="guwen.id"  @tap="goDetail" :data-guwenId="guwen.id">
				<guwen-item :options="guwen"  ></guwen-item>
			</view>
			
		</scroll-view>
		<view style="height:70upx;"></view>
		<navigator :url="'/pages/ruzhu/apply?type='+type" class="bottom">申请入驻</navigator>
		<view class="cu-load load-modal" v-if="isLoading">
			<view class="cuIcon-emojifill text-orange"></view>
			<view class="gray-text">{{loadMoreDefalutText}}</view>
		</view>
    </view>
</template>
<script>
    import guwenItem from './item.vue';

    export default {
        components: {
            guwenItem,
        },
        data() {
            return {
                
				gwList:[],
				type:"gw",
                scrollInto: "",
                showTips: false,
                navigateFlag: false,
                pulling: false,
				page:1,
				cityId:null,
				isGwLeft:true,
				isLoading:false,
				houseid:null,
				connectionFailText:"正在加载",
                refreshIcon: ""
            }
        },
        onLoad(e) {
			this.type=e.type;
			this.houseid=e.houseid;
			
			if(this.type=="sale"){
				uni.setNavigationBarTitle({
				    title: '优秀机构推荐'
				});
			}
		   this.cityId=getApp().globalData.city.id;
			this.loadGwList();
        },
		onShareAppMessage(){
			return {
			      title: '选楼盘，查佣金，看房价'
			    }
		},
		onReachBottom() {
			this.loadGwList();
		},
        methods: {
            //顾问列表
            loadGwList() {
            	var me = this;
				
				if (!me.isGwLeft) {
					uni.showModal({
						content: '已经到底了!',
						showCancel: false
					});
					return;
				}
				me.isLoading=true;
            	uni.request({
            		url: me.$rootUrl+'/Saler/GetList',
            		data: {page:me.page,pageSize:10,type:me.type,status:2,houseid:me.houseid,cityId:me.cityId},
            		method: 'GET',
            		success(res) {
            			me.isLoading=false;
            			if (res.data.success) {
            				 me.gwList = me.gwList.concat(res.data.items);
            				if (me.gwList .length >= res.data.total) {
            					me.isGwLeft = false;
            				} else {
            					me.page++;
            				}
            			} else {
            				uni.showModal({
            					content: '服务器错误!',
            					showCancel: false
            				});
            			}
            		},
            		fail() {
						me.isLoading=false;
            			uni.showModal({
            				content: me.connectionFailText,
            				showCancel: false
            			});
            		}
            	});
            	
            },
            goDetail(e) {
                this.navigateFlag = true;
				var id=e.currentTarget.dataset.guwenid
				var url='/pages/guwen/detail?id='+id;
                uni.navigateTo({
                    url: url
                });
                setTimeout(() => {
                    this.navigateFlag = false;
                }, 200)
            }
        }
    }
</script>

<style lang="scss">
    .box{
		.guwen{
			margin-top:13px;
		}
		.bottom{
			position: fixed;
			bottom:0;
			background-color: #D1372C;
			padding: 6px 0;
			width:100%;
			font-size: 38upx;
			text-align: center;
			color:white;
		}
	}
</style>
